package com.chenjl.api;

import java.util.HashMap;
import java.util.Map;

import org.apache.kafka.common.config.ConfigDef;
import org.apache.kafka.common.config.ConfigDef.Importance;
import org.apache.kafka.common.config.ConfigDef.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * ConfigDef ，定义配置，接收map传递，自带校验工具
 * 生产者，消费者配置，使用校验定义类
 * 
 * 2016-9-14 13:57:41
 * @author chenjinlong
 */
public class TestOnConfigDef {
	private static final Logger logger = LoggerFactory.getLogger(TestOnConfigDef.class);
	
	public static void main(String[] args) {
		ConfigDef defs = new ConfigDef();
		defs.define("config_with_default",Type.STRING,Importance.HIGH,"Configuration with default value.");
		defs.define("config_with_validator",Type.INT,Importance.HIGH,"Configuration with user provided validator.");
		defs.define("config_with_dependents",Type.INT,Importance.HIGH,"Config With Dependents");
		
		Map<String,Object> props = new HashMap<>();
		props.put("config_with_default","some value");
		props.put("config_with_dependents",10);
		props.put("config_with_validator",20);
		Map<String, Object> configs = defs.parse(props);
		
		String a = (String) configs.get("config_with_default");
		int b = (Integer) configs.get("config_with_dependents");
		int c = (Integer) configs.get("config_with_validator");
		
		logger.info("a : {}, b: {}, c: {}",a,b,c);
	}
}